﻿using System;
using System.Diagnostics;
using System.Windows;
using Microsoft.Phone.Reactive;
using Microsoft.Phone.Tasks;
using WindowsPhoneMvp;
using WindowsPhoneMvp.Navigation;
using $safeprojectname$.Views.Second;

namespace $safeprojectname$.Views.Main
{
    public class MainPresenter : Presenter<IMainView, MainViewModel>
    {
        public string PersistMe { get; set; }

        public MainPresenter(IMainView view)
            : base(view)
        {
            //Observe Events
            View.Load += ViewLoad;

            Observable.FromEvent<EventArgs>(View, "LaunchingCamera")
                .Subscribe(x => StartTask<CameraCaptureTask, PhotoResult>(z => 
                    MessageBox.Show("Picture Taken!")));

            //Transient properties
            Transient(() => this).Property(x => x.PersistMe); 
            Transient(x => x.PersistMeToo);
        }

        void ViewLoad(object sender, EventArgs e)
        {
            Model.OnLoaded();
            PersistMe = "test";
            Model.PersistMeToo = "another test";

            Model.NavigatingToViewTwo = Navigate.ByCommand<ISecondView>();
        }

        public override void OnActivated()
        {
        }

        public override void OnNavigationTo(NavigationData navigationData)
        {
            Debug.WriteLine("Navigated to " + navigationData.View);
        }
    }
}
